package com.wanglei.ssm.controller;

import com.wanglei.ssm.domain.Permission;
import com.wanglei.ssm.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;

    @RequestMapping("/findAll.do")
    public ModelAndView findAll(ModelAndView mv) throws Exception {
        List<Permission> list = permissionService.findAll();
        mv.addObject("permissionList",list);
        mv.setViewName("permission-list");
        return mv;
    }

    @RequestMapping("/save.do")
    public String save(Permission p) throws Exception {
        permissionService.save(p);
        return "redirect:findAll.do";
    }

    /**
     * 资源权限管理-详情
     *
     * @param permissionId 权限id
     */
    @RequestMapping("/findById.do")
    public ModelAndView findById(@RequestParam(value = "id")String permissionId,ModelAndView mv) throws Exception{
        mv.addObject("permission",permissionService.findById(permissionId));
        mv.setViewName("permission-show");
        return mv;
    }
}
